package com.smartwebx.ha.web.admin.module.screen.report;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

import oracle.jdbc.OracleCallableStatement;

public class TestDemo {
	public static void main(String[] args){ 
		ConnUtils connUtils = new ConnUtils();
		Connection conn = null;
        CallableStatement statement = null;
        ResultSet rs = null;
        int j = 0;
        StringBuffer sb = new StringBuffer();
        String s = null;
        try {
			conn = connUtils.getConnection();
			statement = conn.prepareCall("{?=call JSSFK.JCROSSDAY(?,?,?)}");
            statement.registerOutParameter(1, oracle.jdbc.OracleTypes.CURSOR);
            statement.setString(2, "63101130");
            statement.setString(3, "2012");
            statement.setString(4, "0");
            statement.executeUpdate();
            rs = ((OracleCallableStatement) statement).getCursor(1);
            ResultSetMetaData rsmd = null;
            rsmd = rs.getMetaData();
            int columnCount = rsmd.getColumnCount();
			while(rs.next()){
				//'[{"field":"col1","header":"列名1"},{"field":"col2","header":"列名2"},{"field":"col3","header":"列名3"}]'
				if(j==0){
					sb.append("[");
					for(int i = 1 ; i<= columnCount ; i++){ 
						sb.append("{\"field\":\"col"+i);
						sb.append("\",\"header\":\"");
						String columnName = rsmd.getColumnName(i); 
						sb.append(columnName+"\"},");
						//System.out.print(columnName+" "); 
					}
					s = sb.toString();
					s = s.substring(0, s.length()-1)+"]";
					System.out.println(s);
					j = 1;
				}
				for(int i = 1 ; i<= columnCount ; i++){ 
					String columnValue = rs.getString(i); 
					//System.out.print(columnValue+" ");   
				} 
				//System.out.println();
			} 
		} catch (SQLException e) { 
			System.out.println("数据库连接失败"); 
		} 
	}
}
